package sy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sy.pageModel.BaseEntity;
import sy.pageModel.DataGrid;
import sy.pageModel.Json;
import sy.pageModel.Tourism;
import sy.service.MassageServiceI;
import sy.service.TourismServiceI;
import sy.util.StringUtil;

import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2016-07-20.
 */
@Controller
@RequestMapping("/tourismController")
public class TourismController extends BaseController {

    @Autowired
    private TourismServiceI tourismService;
    @RequestMapping("/datagrid")
    @ResponseBody
    public DataGrid datagrid(Tourism curr) throws Exception {

        return tourismService.findMassageList(curr);
    }

    @RequestMapping("/add")
    @ResponseBody
    public Json add(Tourism curr, HttpSession session) {
        int rows = 0;
        try {
            Tourism tour = tourismService.addTourism(curr);
            if (tour != null) rows = 1;
        } catch (Exception e) {
            rows = 0;
        }
        Json js = StringUtil.findJson(rows, "添加");
        return js;
    }

    @RequestMapping("/del")
    @ResponseBody
    public Json remove(Tourism curr, HttpSession session) {
        int rows = 0;
        try {
            Tourism tour = tourismService.deleteTourism(curr);
            if (tour != null) rows = 1;
        } catch (Exception e) {
            rows = 0;
        }
        Json js = StringUtil.findJson(rows, "删除");
        return js;
    }

    @RequestMapping("/edit")
    @ResponseBody
    public Json edit(Tourism curr, HttpSession session) {
        int rows=0;
        try {
            Tourism tour=tourismService.editTourism(curr);
            if (tour!=null) rows=1;
        } catch (Exception e) {
           rows=0;
        }
        Json js= StringUtil.findJson(rows,"修改");
        return js;
    }
}
